package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:char(11);unique;not null;comment:手机号"`
	Password string `gorm:"type:char(32);comment:密码"`
	NickName string `gorm:"type:varchar(50);not null;comment:昵称"`
	Status   int    `gorm:"type:int(11);default:1;comment:状态：1正常 2禁用"`
}

type UserRealname struct {
	gorm.Model
	UserId   int    `gorm:"type:int(11);not null;comment:用户"`
	Realname string ` gorm:"type:varchar(50);not null;comment:真实姓名"`
	IdCard   string `gorm:"type:char(18);not null;comment:身份证号"`
}

// 用户登录
func (u *User) GetUserInfoByMobile() error {
	return DB.Where("mobile = ?", u.Mobile).Find(&u).Limit(1).Error
}

// 用户注册
func (u *User) Create() error {
	return DB.Create(&u).Error
}

// 查找实名认证userId
func (ur *UserRealname) GetUserRealnameByUserId() error {
	return DB.Where("user_id = ?", ur.UserId).Find(&ur).Limit(1).Error
}

// 认证
func (ur *UserRealname) Create() error {
	return DB.Create(&ur).Error
}
